﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CapaPresentacion.Converters;

namespace CapaPresentacion.Controles
{
    /// <summary>
    /// Lógica de interacción para ElegirSiNo.xaml
    /// </summary>
    public partial class ElegirSiNo : UserControl
    {
        // Using a DependencyProperty as the backing store for ValorSeleccionado.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ValorSeleccionadoProperty;

        static ElegirSiNo()
        {
            ValorSeleccionadoProperty = DependencyProperty.Register(
                                                                        "ValorSeleccionado",
                                                                        typeof(Boolean?),
                                                                        typeof(ElegirSiNo),
                                                                        new FrameworkPropertyMetadata(null,
                                                                            new PropertyChangedCallback(OnValorSeleccionadoChanged)));
        }

        public ElegirSiNo()
        {
            InitializeComponent();

        //    this.chkNoContesta.IsChecked = true;

            //Binding b1 = new Binding();
            //b1.Source = this;
            //b1.Path = new PropertyPath(ElegirSiNo.ValorSeleccionadoProperty);
            //b1.Mode = BindingMode.TwoWay;

            //this.SetBinding(RadioButton.IsCheckedProperty, b1);
        }

        public string Etiqueta
        {
            get { return lbl.Content.ToString(); }

            set { lbl.Content = value; }
        }

        public Boolean? ValorSeleccionado
        {
            get
            {
                return (Boolean?)GetValue(ValorSeleccionadoProperty);
            }
            set
            {
                SetValue(ValorSeleccionadoProperty, value);
            }
        }

        private static void OnValorSeleccionadoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ElegirSiNo control = (ElegirSiNo)d;

            switch ((Boolean?)e.NewValue)
            {
                case true:
                    control.chkSi.IsChecked = true;
                    break;

                case false:
                    control.chkNo.IsChecked = true;
                    break;

                default:
                   // control.chkNoContesta.IsChecked = true;
                    break;
            }
        }

        private void chk_Click(object sender, RoutedEventArgs e)
        {
            RadioButton rb = (RadioButton)sender;

            switch (rb.Name)
            {
                case "chkSi":
                    ValorSeleccionado = true;
                    break;              
                case "chkNo":           
                    ValorSeleccionado = false;
                    break;              
                //case "chkNoContesta":   
                //    ValorSeleccionado = null;
                //    break;
            }
        }
    }
}
